﻿using System;
using System.Linq;
using System.Linq.Expressions;
using OutDbContext;
using User.Api.Helpers;

namespace User.Api.BizExtensions
{
    public static class BookOrderExtensions
    {
        public static IQueryable<BookOrder> IsStatus(this IQueryable<BookOrder> source,
            params BookStatus[] bookStatuses)
        {
            if (bookStatuses.Length <= 0)
            {
                return source;
            }

            var intOrderStatus = (int)bookStatuses[0];
            Expression<Func<BookOrder, bool>> expression = x => x.BookStatus == intOrderStatus;

            for (int i = 1; i < bookStatuses.Length; i++)
            {
                var intOrderStatus2 = (int)bookStatuses[i];
                var expressionHelper = new ExpressionHelper<BookOrder>();
                expression = expressionHelper.BuildQueryOr(expression, x => x.BookStatus == intOrderStatus2);
            }

            return source.Where(expression);
        }

        public enum BookStatus
        {
            未发起预约 = 0,
            预约成功 = 1,
            预约失败 = 2,
            取消预约成功 = 3,
            取消预约失败 = 4
        }
    }
}